package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-07-08
 * Time: 18:58
 */
public class DeleteBook implements IOperation {
    public void work(BookList bookList){
        int i=0;
        int pos=-1;
        int currentSize= bookList.getUsedSize();
        System.out.println("*****删除界面*****");
        System.out.println("请输入你要删除的书的书名：");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        for (i = 0; i < currentSize; i++) {
            Book book=bookList.getBooks(i);
            if(name.equals(book.getName())){
                pos=i;
                break;
            }
        }
        if(i==bookList.getUsedSize()){
            System.out.println("没有这本书哦！");
        }

        for(int j=pos;j<currentSize-1;j++){
            Book book=bookList.getBooks(j+1);
            bookList.setBooks(book,j);
        }
        bookList.setUsedSize(currentSize-1);
        System.out.println("删除成功！");

    }
}
